<script setup lang="ts">
import LiuUserInfo from '@/components/LiuUserInfo.vue'
import type { TbMessage, TbMessageReply } from '@/types/messageapi'
import type { BaseDataResult, BaseResult, PageBean, PageVO } from '@/types/BaseResult'
import { Api } from '@/types/Api'
import { Tools } from '@/types/Tools'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
import { ref, onMounted } from 'vue'
import { NCard, useMessage } from 'naive-ui'

const route = useRoute()

const uid = route.params.uid
console.log('用户id：', uid)

const firstLoad = ref(true)

const message = useMessage()

const toDetail = (mid: number) => {
  router.push(`/message/${mid}`)
}

//#region 查询帖子
const page = ref({ pageNumber: 1, pageSize: 10 } as PageBean)
const list = ref([] as TbMessage[])
const queryInfo = ref({ order: 1, info: '' })

//#region 查询评论
const queryReply = () => {
  Api.get(
    `/reply/${uid}/${page.value.pageSize}/${page.value.pageNumber}/${queryInfo.value.order}`,
    {},
    (data: BaseDataResult<PageVO<TbMessage>>) => {
      if (data.success) {
        list.value = data.data.list
        page.value = data.data.pageBean
        return
      }
      message.error(data.message)
    },
  )
}
//#endregion

onMounted(() => {
  queryReply()
})
</script>

<template>
  {{ list }}
  <div>
    <div v-for="d in list" :key="d.uid">
      <div class="content">
        <div>
          <NAvatar round :src="Api.userlogo(d.uid)"></NAvatar>
        </div>
        <div>
          <div>
            {{ Tools.formatDate(d.lastupdate) }}
            - {{ d.info }}
            <span>({{ d.praise }})</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped></style>
